# Reference: <https://postmarketos.org/devicepkg>
# Maintainer: Richard Acayan <mailingradian@gmail.com>
pkgname=device-google-sargo
pkgdesc="Google Pixel 3a"
pkgver=7
pkgrel=0
url="https://postmarketos.org"
license="MIT"
arch="aarch64"
options="!check !archcheck"
depends="
	alsa-ucm-conf-qcom-sdm670
	linux-postmarketos-qcom-sdm670
	make-dynpart-mappings
	mkbootimg
	postmarketos-base
	soc-qcom-sdm845
	soc-qcom-sdm845-qbootctl
"
makedepends="devicepkg-dev"
source="
	10-unl0kr-msm.conf
	81-libssc-google-sargo.rules
	90-feedbackd-drv2624.rules
	deviceinfo
	hexagonrpcd-adsp-sensorspd.confd
	modules-initfs
	no-hexagonrpcd-on-suspend.sh
	q6voiced.conf
"
subpackages="
	$pkgname-nonfree-firmware:nonfree_firmware
	$pkgname-nonfree-firmware-openrc:nonfree_firmware_openrc
	"

build() {
	devicepkg_build $startdir $pkgname
}

package() {
	devicepkg_package $startdir $pkgname

	install -Dm644 "$srcdir"/90-feedbackd-drv2624.rules \
		-t "$pkgdir"/usr/lib/udev/rules.d
	install -Dm644 "$srcdir"/10-unl0kr-msm.conf \
		"$pkgdir"/etc/unl0kr.conf.d/10-unl0kr-msm.conf
}

nonfree_firmware() {
	pkgdesc="Proprietary firmware blobs for the Google Pixel 3a"
	depends="
		firmware-google-sargo
		hexagonrpcd
		linux-firmware-ath10k
		linux-firmware-qca
		linux-firmware-qcom
		soc-qcom-sdm845-modem
		soc-qcom-sdm845-nonfree-firmware
	"
	# Sensors depend on ADSP firmware and the sensors registry served over FastRPC.
	install -Dm644 "$srcdir"/81-libssc-google-sargo.rules \
		"$subpkgdir"/usr/lib/udev/rules.d/81-libssc-google-sargo.rules
}

nonfree_firmware_openrc() {
	replaces="hexagonrpcd-openrc"
	install_if="$pkgname-nonfree-firmware=$pkgver-r$pkgrel openrc"
	# Enable HexagonRPCD by default, but not if the user installed this
	# package then disabled it.
	install="$subpkgname.post-install"
	replaces="hexagonrpcd-openrc"
	# The FastRPC service is only enabled when non-free firmware is installed.
	install -Dm755 "$srcdir"/no-hexagonrpcd-on-suspend.sh \
		"$subpkgdir"/etc/elogind/system-sleep/no-hexagonrpcd-on-suspend.sh
	# The q6voiced configuration can only be used if the ADSP is brought up
	# via non-free firmware.
	install -Dm644 "$srcdir"/q6voiced.conf "$subpkgdir"/etc/conf.d/q6voiced
	# Sensors depend on ADSP firmware and the sensors registry served over FastRPC.
	install -Dm644 "$srcdir"/hexagonrpcd-adsp-sensorspd.confd \
		"$subpkgdir"/etc/conf.d/hexagonrpcd-adsp-sensorspd
}

sha512sums="
f700af3145b79d1ef9edfb22982899b25cabfb212f9620dcbd3a2e6f44b5ad591e0a66056c6fcd66c3fde89a2b5f551e8a8fe2e65cf0e2a48adec57c027d7825  10-unl0kr-msm.conf
089ce0acba4e1d789e337bedfca7570796a6416e7230ae9b8fc6b625747a40dbb064b1a707877cd6b7bdc73844c6571316e2ec0746a77060f13d98c52fdbfc00  81-libssc-google-sargo.rules
016d398155f2344417f5e5649a361719ba6e53e593c501b5df39114cdd284302b9bf8686a39817aee0c08fec95b3ab613c181d6cc9596299aaf7fd05dbe0c3dd  90-feedbackd-drv2624.rules
ad032b1a35cfcd4fc0c8df988430ee97b711e785b86cca68b7552b23a9a2e2b6b97c327e3415a575db47ad6c1f86ded18df5553acaae63010057d89b8c16135e  deviceinfo
b6208c254b6e44ac4f6d748a38cc6b05da0db2c90235ada2011b138b82ccc3372687df2f5ad97e885e9eea135216a3c52266a08a7f4eb323e62e799f6f82ec7b  hexagonrpcd-adsp-sensorspd.confd
3213a3586c25cef843a47e2446179ff73acad6421826a64bedb6b9800d30673503d0ea6b3fcc8cfbdcdcaf0926755a489323fce9d14d4411799e6988144b3518  modules-initfs
2972005a9cf6ca57061965075593dddfa8ee479bc6c21cd41851b1a14768cb1cddbd31a17975ae17adc36d40d294ccbc6bf83defbd69fc7b363f638d8564fbbc  no-hexagonrpcd-on-suspend.sh
3a4a9322839d4b3ef9d79668a37840a9f444954759ae3c512e694051d2f9a2573db42ad6c4c1a5c75eeb861232a27ba1a8cef9b503decd54ead25a96e3dd6f98  q6voiced.conf
"
